package com.uchengwang.ui.cm_ui.ucity.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.ucity.cityBean.UcityInfoBean;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;



/**
 * Created by U城网 on 2017/11/30.
 */

public class ExchangeThingAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;
    private int TYPE_CONTENT = 1;
    private List<UcityInfoBean> list = new ArrayList<>();

    public ExchangeThingAdapter(Context context){
        this.context = context;
    }

    public void setData(List<UcityInfoBean> list){
        this.list = list;
        notifyDataSetChanged();
    }

    public List<UcityInfoBean> getData(){
        return list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ExchangeThingAdapter.ExchangeVH viewHolder = null;
        View view = LayoutInflater.from(context).inflate(R.layout.view_exchange_item, parent, false);
        viewHolder = new ExchangeVH(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder h, int position) {
        ExchangeVH holder = (ExchangeVH) h;

        final UcityInfoBean bean = list.get(position);
        String cover = bean.getPubShortCover();

        if (!TextUtils.isEmpty(cover)){
            ImageManager.getInstance().loadImage(context, holder.cover, cover, ImageManager.ImageType.ROUND);
        }else {
            ImageManager.getInstance().loadImage(context, holder.cover, R.drawable.default_image, ImageManager.ImageType.ROUND);
        }

        holder.title.setText(bean.getPubTitle());
        holder.location.setText(bean.getUniName());
        int lowPrice = bean.getItemLowPrice();
        int highPrice = bean.getItemHighPrice();
        if (lowPrice <=0 && highPrice<=0){
            holder.des.setText("面议");
        }else if (lowPrice >0 && highPrice>0){
            if (lowPrice == highPrice){
                holder.des.setText(lowPrice+"");
            }else {
                holder.des.setText(lowPrice+" -- "+highPrice);
            }
        }else {
            holder.des.setText((lowPrice >0 ? lowPrice : highPrice) + "");
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
               //跳转到社团纳新宣传详情页
//               Intent intent = new Intent(context, UCity3Activity.class);
//               intent.putExtra(BaseConfig.ID, bean.getId());
//               intent.putExtra(BaseConfig.PUB_TYPE, bean.getPubType());
//               context.startActivity(intent);
                }
            });

    }


    @Override
    public int getItemCount() {
        return list.size();
    }


    class ExchangeVH extends RecyclerView.ViewHolder {
        private View itemView;
        private ImageView cover;//背景图 logo
        private TextView title, des, location;

        public ExchangeVH(View view) {
            super(view);
            itemView = view;
            AutoUtils.autoSize(view);

            title = (TextView) view.findViewById(R.id.exchange_title);
            cover = (ImageView) view.findViewById(R.id.exchange_cover);
            des = (TextView) view.findViewById(R.id.exchange_des);
            location = (TextView) view.findViewById(R.id.exchange_location);

        }
    }
}
